<?php
class Backend_Designer_Code 
{
	/**
	 * Get possible actions from Controller class.
	 * Note! Code accelerator (eaccelerator, apc, xcache, etc ) should be disabled to get comment line.
	 * Method returns only public methods that ends with "Action" 
	 * @param string $controllerName
	 * @return array like array(
	 * 		array(
	 * 			'name' => action name without "Action" postfix
	 * 			'comment'=> doc comment
	 * 		)
	 * )
	 */
	static public function getPossibleActions($controllerName)
	{
		$reflector = new ReflectionClass($controllerName);
		
		if(!$reflector->isSubclassOf('Backend_Controller')){
			return array();
		}
		
		$actions = array();
		$methods = $reflector->getMethods(ReflectionMethod::IS_PUBLIC);
		
		if(!empty($methods))
		{
			foreach ($methods as $method)
			{
				if(substr($method->name , -6) !== 'Action')
					continue;
					
				$actions[] = array(
					'name'=>substr($method->name , 0 , -6),
					'comment'=>self::_clearDocSymbols($method->getDocComment()) 
				);
			}
		}
		return $actions;
	}
	/**
	 * Clear string from comment symbols
	 * @param string $string
	 */
	static protected function _clearDocSymbols($string){
		return str_replace(array('/*','*/','*') , '' , $string);
	}
}